/*
 * 
 * 
 * 
 */
package com.hboxs.asl.entity;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import com.hboxs.asl.util.DateUtils;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Entity - 充值
 */
@Entity
@Table(name = "xx_trade")
@SequenceGenerator(name = "sequenceGenerator", sequenceName = "xx_trade_sequence")
public class Trade extends BaseEntity {

    private static final long serialVersionUID = -6209590619136943215L;


    /**
     * 流水号
     */
    private String tn;

    /**
     * 用户
     */
    private Member member;

    /**
     * 充值价格
     */
    private BigDecimal amount;

    /**
     * 充值前积分
     */
    private BigDecimal prePoint;

    /**
     * 充值后积分
     */
    private BigDecimal afterPoint;

    /**
     * 转换比例
     */
    private BigDecimal percentage;

    /**
     * 对消费，支付方式分类
     */
    private Style style;

    /**
     * 方式
     */
    public enum Style {
        /**
         * 消费
         */
        waste,
        /**
         * 充值
         */
        pay;

        private static Map<String, Style> map = new HashMap<>();

        static {
            map.put("消费", waste);
            map.put("充值", pay);
        }

        @JsonCreator
        public static Style forValue(String value) {
            return map.get(value);
        }

        @JsonValue
        public String toValue() {
            for (Map.Entry<String, Style> entry : map.entrySet()) {
                if (entry.getValue() == this) {
                    return entry.getKey();
                }
            }

            return "";
        }
    }

    /**
     * 流水状态
     */
    public enum TradeStatus {
        /**
         * 未完成
         */
        create,

        /**
         * 已完成
         */
        done;

        private static Map<String, TradeStatus> map = new HashMap<>();

        static {
            map.put("未完成", create);
            map.put("已完成", done);
        }

        @JsonCreator
        public static TradeStatus forValue(String value) {
            return map.get(value);
        }

        @JsonValue
        public String toValue() {
            for (Map.Entry<String, TradeStatus> entry : map.entrySet()) {
                if (entry.getValue() == this) {
                    return entry.getKey();
                }
            }

            return "";
        }
    }

    private TradeStatus tradeStatus;

    /**
     * 完成时间
     */
    private Date completeDate;

    /**
     * 获取流水号
     *
     * @return 流水号
     */
    public String getTn() {
        return tn;
    }

    /**
     * 设置流水号
     *
     * @param tn 流水号
     */
    public void setTn(String tn) {
        this.tn = tn;
    }

    /**
     * 设置类型
     *
     * @param style 类型
     */
    public void setStyle(Style style) {
        this.style = style;
    }

    /**
     * 获取类型
     *
     * @return 类型
     */
    public Style getStyle() {
        return style;
    }

    /**
     * 获取充值价格
     *
     * @return 充值价格
     */
    public BigDecimal getAmount() {
        return amount;
    }

    /**
     * 设置充值价格
     *
     * @param amount 充值价格
     */
    public void setAmount(BigDecimal amount) {
        this.amount = amount;
    }

    /**
     * 获取会员
     *
     * @return 会员
     */
    @ManyToOne(fetch = FetchType.LAZY)
    public Member getMember() {
        return member;
    }

    /**
     * 设置会员
     *
     * @param member 会员
     */
    public void setMember(Member member) {
        this.member = member;
    }

    /**
     * 获取流水状态
     *
     * @return 流水状态
     */
    public TradeStatus getTradeStatus() {
        return tradeStatus;
    }

    /**
     * 设置流水状态
     *
     * @param tradeStatus 流水状态
     */
    public void setTradeStatus(TradeStatus tradeStatus) {
        this.tradeStatus = tradeStatus;
    }

    /**
     * 获取完成时间
     *
     * @return 完成时间
     */
    public Date getCompleteDate() {
        return completeDate;
    }

    /**
     * 设置完成时间
     *
     * @param completeDate 完成时间
     */
    public void setCompleteDate(Date completeDate) {
        this.completeDate = completeDate;
    }

    public BigDecimal getPrePoint() {
        return prePoint;
    }

    public void setPrePoint(BigDecimal prePoint) {
        this.prePoint = prePoint;
    }

    public BigDecimal getAfterPoint() {
        return afterPoint;
    }

    public void setAfterPoint(BigDecimal afterPoint) {
        this.afterPoint = afterPoint;
    }

    public BigDecimal getPercentage() {
        return percentage;
    }

    public void setPercentage(BigDecimal percentage) {
        this.percentage = percentage;
    }

    @Transient
    public String getCreateDateF(){
        return DateUtils.dateToHMS(super.getCreateDate());
    }
}